home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / frontend_implementation / startup.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  3.0 KB  |  98 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. from threading import Thread, Event
  19. import util
  20. import frontend
  21. from gtcache import gettext as _
  22. from gtcache import ngettext
  23.  
  24. class _Search:
  25.     def __init__(self, path):
  26.         self.cancelled = Event()
  27.         self.path = path
  28.         self.last = None
  29.  
  30.     def run(self):
  31.         thread = Thread(target=self.runSearch)
  32.         thread.setDaemon(True)
  33.         thread.start()
  34.  
  35.     def cancel(self):
  36.         self.cancelled.set()
  37.  
  38.     # Alternate thread.
  39.     def progressCallback(self, files, videos):
  40.         if self.cancelled.isSet():
  41.             return False
  42.         frontend.jsBridge.updateSearchProgress(_("(parsed %d files - found %d videos)") % (files, videos))
  43.         return True
  44.  
  45.     # Alternate thread.
  46.     def runSearch (self):
  47.         self.files = util.gatherVideos(self.path, self.progressCallback)
  48.         if not self.cancelled.isSet():
  49.             count = len(self.files)
  50.             frontend.jsBridge.searchFinished(ngettext("%d video found", "%d videos found", count) % (count,))
  51.  
  52.     def getFiles (self):
  53.         if self.cancelled.isSet():
  54.             return None
  55.         else:
  56.             return self.files
  57.  
  58. search = None
  59. callback = None
  60.  
  61. def doSearch(path):
  62.     global search
  63.     search = _Search(path)
  64.     search.run()
  65.  
  66. def cancelSearch():
  67.     search.cancel()
  68.     frontend.jsBridge.searchCancelled("")
  69.  
  70. def finishStartup():
  71.     if search:
  72.         terminationCallback(search.getFiles())
  73.     else:
  74.         terminationCallback(None)
  75. #    if widgetTree['radiobutton-startup-autostart-yes'].get_active():
  76. #     config_home = os.environ.get ('XDG_CONFIG_HOME',
  77. #                       '~/.config')
  78. #     config_home = os.path.expanduser (config_home)
  79. #     autostart_dir = os.path.join (config_home, "autostart")
  80. #     destination = os.path.join (autostart_dir, "democracyplayer.desktop")
  81. #     try:
  82. #         os.makedirs(autostart_dir)
  83. #     except:
  84. #         pass
  85. #     try:
  86. #         shutil.copy (resource.sharePath('applications/democracyplayer.desktop'), autostart_dir)
  87. #     except:
  88. #         pass
  89. #    try:
  90. #     dialog.destroy()
  91. #    except:
  92. #     pass
  93.  
  94. def performStartupTasks(terminationCallback):
  95.     global callback
  96.     callback = terminationCallback
  97.     frontend.jsBridge.performStartupTasks(os.path.expanduser("~"))
  98.